//
//  LGTTimeSelectVC.swift
//  KJLGT
//
//  Created by jenkin on 2019/8/24.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit
import WisdomHUD

class LGTRWZTimeSelectVC: LGTBaseVC {

    let timePick:UIDatePicker = UIDatePicker.init()
    var currentDateStr:String?
    var clickBlock:ClickPostNameModelBlock?
    var path:IndexPath?
    var isDate:Bool = false //是否只是日期类型
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //self.timePick.datePickerMode  = UIDatePicker.Mode.dateAndTime
//        self.timePick.minimumDate = Date.init()
//        if currentDateStr?.count ?? 0 > 0{
//            let date:Date = BaseUtil.stringConvertDate(string: self.currentDateStr!)
//            self.timePick.date = date
//        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if self.isDate == true{
            self.timePick.maximumDate = Date.init()
        }else{
             self.timePick.minimumDate = Date.init()
        }
        
        if currentDateStr?.count ?? 0 > 0{
            let date:Date = BaseUtil.stringConvertDate(string: self.currentDateStr!)
            self.timePick.date = date
        }
    }
    
    override func setUI() {
        super.setUI()
        self.view.backgroundColor = BlackAlphaColor
        let backView:UIView = UIView.init()
        backView.backgroundColor = UIColor.white
        self.view.addSubview(backView)
        backView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalTo(0)
            make.height.equalTo(SizeFit(210) + IPHONETabbar_DIS)
        }
        
        let topView:UIView = UIView.init()
        topView.backgroundColor = ColorUtil(color: 0xFFDFA0)
        backView.addSubview(topView)
        topView.snp.makeConstraints { (make) in
            make.left.right.top.equalTo(0)
            make.height.equalTo(SizeFit(48))
        }
        
        let clostBtn = LGTViewCreateUtil.share.createTextLGTButton(title: "取消", font: Font_Normal_18, color: TextColor, selectedColor: TextColor, dW: SizeFitFloat(5), dH: SizeFitFloat(5))
        topView.addSubview(clostBtn)
        clostBtn.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(14))
            make.height.equalTo(SizeFitFloat(18))
            make.width.equalTo(SizeFit(40))
            make.centerY.equalTo(topView)
        }
        clostBtn.backgroundColor = UIColor.clear
        
        let sureBtn = LGTViewCreateUtil.share.createTextLGTButton(title: "确定", font: Font_Normal_18, color: YellowColor, selectedColor: YellowColor, dW: SizeFitFloat(5), dH: SizeFitFloat(5))
        topView.addSubview(sureBtn)
        sureBtn.snp.makeConstraints { (make) in
            make.right.equalTo(-SizeFit(14))
            make.height.equalTo(SizeFitFloat(18))
            make.width.equalTo(SizeFit(40))
            make.centerY.equalTo(topView)
        }
        sureBtn.backgroundColor = UIColor.clear
        
        
        
        backView.addSubview(self.timePick)
        if self.isDate == true{
            self.timePick.datePickerMode = UIDatePicker.Mode.date
        }
        
//        self.pickView.delegate = self as UIPickerViewDelegate
//        self.pickView.dataSource = self
        self.timePick.snp.makeConstraints { (make) in
            make.left.bottom.right.equalTo(0)
            make.top.equalTo(SizeFit(48))
        }
        
        clostBtn.addTarget(self, action: #selector(closeAction), for: UIControl.Event.touchUpInside)
        sureBtn.addTarget(self, action: #selector(sureAction), for: UIControl.Event.touchUpInside)
    }

    
    @objc func closeAction(){
        self.dismiss(animated: false, completion: nil)
    }
    
    @objc func sureAction(){
        let dateStr:String = BaseUtil.dateConvertString(date: self.timePick.date)
        if self.clickBlock != nil{
            var model:PostNameModel = PostNameModel()
            model.name = dateStr
            self.clickBlock!(model, self.path!)
        }
        self.dismiss(animated: false, completion: nil)
    }
}
